package com.ce.pms.house.dao.impl;



import org.hibernate.Query;

import com.ce.pms.base.dao.impl.PmsBaseDaoImpl;
import com.ce.pms.house.dao.IExamineApproveDao;
import com.ce.pms.house.model.ExamineApproveDomain;
import com.ce.util.BlankUtil;
import com.sitechasia.webx.core.support.Page;

public class ExamineApproveDaoImpl extends PmsBaseDaoImpl<ExamineApproveDomain> implements
		IExamineApproveDao {
	/**
	 * 方法描述: 根据退伙登记ＩＤ和审核角色查询ExamineApproveDomain
	 * @author 胡煦
	 * Create on:2008-9-4
	 * @param goOutId,approveRole
	 * @return ExamineApproveDomain
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public ExamineApproveDomain getExamineApproveBy(Long goOutId,String approveRole){
		String hql = "from ExamineApproveDomain ed where ed.goOut.id = ? and ed.approveRole.value = ? and validity = 1";
		Query query = createQuery(hql, new Object[]{goOutId,approveRole});
		if(!BlankUtil.isBlank(query.list())){
			return (ExamineApproveDomain)query.list().get(0);
		}
		return null;
	}

	/**
	 * 方法描述: 根据用户ＩＤ查询用户姓名
	 * @author 胡煦
	 * Create on:2008-9-4
	 * @param userId
	 * @return userName
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
//	public String getUserNameById(Long userId){
//		String hql = "select su.USERNAME from SEC_USERINFO su where su.USER_ID = ?";
//		Query query = createSQLQuery(hql, userId);
//		return (String) query.list().get(0);
//	}

	/**
	 * 方法描述:根据名字模糊查询或查询所有用户
	 * @author 胡煦
	 * Create on:2008-9-4
	 * @param
	 * @return Page
	 * Edit author:
	 * Edit on:
	 * 修改原因：
	 */
	public Page getAllUser(String userName,int pageNo, int pageSize){
		String sql = "select * from SEC_USERINFO";
		if(!BlankUtil.isBlank(userName)){
			sql = "select * from SEC_USERINFO su where su.USERNAME like ?";
			return this.pagedSqlQueryByPageNo(sql, pageNo, pageSize,new Object[]{"%"+userName+"%"});
		}
		return this.pagedSqlQueryByPageNo(sql, pageNo, pageSize);
	}
}
